package app.form.component;

import java.util.List;

public abstract class AbstractSelectComponent extends AbstractComponent {
    private List<Float> items;
    public AbstractSelectComponent (String name, String title, List<Float> items) {
        this.items = items;
        this.title = title;
        this.name = name;
    }
    protected abstract String getType ();
    protected String getTopHTML() {
        return "";
    }
    protected String getBottomHTML() {
        return "";
    }
    protected abstract String getItemHTML (Float value, int index);
    @Override
    public String renderHTML () {
        StringBuilder s = new StringBuilder ();
        s.append("<div class='" + getType() + "' id='" + getName() + "'>");
        s.append(getTitleHTML());
        s.append("<div class='" + getType() + "_group'>");
        s.append(getTopHTML());
        for (int i = 0; i < items.size(); ++ i) {
            s.append(getItemHTML(items.get(i), i));
        }
        s.append(getBottomHTML());
        s.append("</div>");
        s.append("</div>");
        return s.toString();
    }
    @Override
    public String renderJS() {
        return "function "+getName()+"_value() { return "+getType()+"Value('"+getName()+"'); }\r\n";
    }
}
